<template>
  <a-layout-sider
    v-model="collapsed"
    :class="['sider', isDesktop() ? null : 'shadow', theme, fixSiderbar ? 'ant-fixed-sidemenu' : null]"
    width="208px"
    :collapsible="collapsible"
    :trigger="null"
  >
    <!--    <logo />-->
    <s-menu
      class="subMenu"
      :collapsed="collapsed"
      :menu="menus"
      :theme="theme"
      :mode="mode"
      :style="smenuStyle"
      style="padding: 0; height: calc(100vh - 60px); overflow-x: hidden; overflow-y: auto"
      @select="onSelect"
      @updateMenuTitle="onUpdateMenuTitle"
    />
  </a-layout-sider>
</template>

<script>
import ALayoutSider from 'ant-design-vue/es/layout/Sider'
import Logo from '../tools/Logo'
import SMenu from './index'
import { mixin, mixinDevice } from '@/utils/mixin.js'

export default {
  name: 'SideMenu',
  components: { ALayoutSider, Logo, SMenu },
  mixins: [mixin, mixinDevice],
  props: {
    mode: {
      type: String,
      required: false,
      default: 'inline',
    },
    theme: {
      type: String,
      required: false,
      default: 'dark',
    },
    collapsible: {
      type: Boolean,
      required: false,
      default: false,
    },
    collapsed: {
      type: Boolean,
      required: false,
      default: false,
    },
    menus: {
      type: Array,
      required: true,
    },
  },
  computed: {
    smenuStyle() {
      const style = { padding: '0' }
      if (this.fixSiderbar) {
        // style['height'] = 'calc(100% - 59px)'
        style['overflow'] = 'auto'
        style['overflow-x'] = 'hidden'
      }
      return style
    },
  },
  methods: {
    onSelect(obj) {
      this.$emit('menuSelect', obj)
    },
    onUpdateMenuTitle(obj) {
      this.$emit('updateMenuTitle', obj)
    },
  },
}
</script>
<style lang="less" scoped>
/* update_begin author:sunjianlei date:20190509 for: 修改侧边导航栏滚动条的样式 */
.sider {
  @scrollBarSize: 10px;

  ul.ant-menu {
    /* 定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
    &::-webkit-scrollbar {
      width: @scrollBarSize;
      height: @scrollBarSize;
      background-color: transparent;
      display: none;
    }

    & .-o-scrollbar {
      display: none;
    }

    /* 兼容IE */
    -ms-overflow-style: none;
    -ms-scroll-chaining: chained;
    -ms-content-zooming: zoom;
    -ms-scroll-rails: none;
    -ms-content-zoom-limit-min: 100%;
    -ms-content-zoom-limit-max: 500%;
    -ms-scroll-snap-type: proximity;
    -ms-scroll-snap-points-x: snapList(100%, 200%, 300%, 400%, 500%);

    /* 定义滚动条轨道 */
    &::-webkit-scrollbar-track {
      background-color: transparent;
    }

    /* 定义滑块 */
    &::-webkit-scrollbar-thumb {
      border-radius: @scrollBarSize;
      background-color: #eee;
      box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.1);

      &:hover {
        background-color: #dddddd;
      }

      &:active {
        background-color: #bbbbbb;
      }
    }
  }

  /** 暗色系滚动条样式 */
  &.dark ul.ant-menu {
    &::-webkit-scrollbar-thumb {
      background-color: #666666;

      &:hover {
        background-color: #808080;
      }

      &:active {
        background-color: #999999;
      }
    }
  }
}

/* update_end author:sunjianlei date:20190509 for: 修改侧边导航栏滚动条的样式 */
</style>

<!-- update_begin author:sunjianlei date:20190530 for: 选中首页的时候不显示背景颜色 -->
<style lang="less">
@GBcolor: #3154a4;

.subMenu .ant-menu,
.subMenu .ant-layout-sider-children {
  background-color: @GBcolor !important;
}

.ant-menu-submenu-title,
.ant-menu-item span,
.ant-menu-item a,
.ant-menu:first-child > a {
  color: #fff !important;
}
.subMenu {
  .ant-menu-item-selected {
    background-color: @GBcolor !important;
    a {
      color: rgb(226, 128, 3) !important;
      span {
        color: rgb(226, 128, 3) !important;
      }
    }
  }
  .ant-menu-sub {
    .ant-menu-item-selected {
      background-color: white !important;
      padding-left: 20px !important;
      border-radius: 20px;
      text-align: center;
      a {
        color: rgb(226, 128, 3) !important;
        span {
          color: rgb(226, 128, 3) !important;
        }
      }
    }
  }
}

 .isSeparate{
   background-image: linear-gradient(to right, transparent, rgba(166, 166, 166, 0.5), transparent);
   background-size: 90% 1px;
   background-position: bottom;
   background-repeat: no-repeat;
 }

.subMenu > .ant-menu-item > a {
  margin-bottom: 4px;
}

.subMenu > .ant-menu-submenu > .ant-menu-submenu-title {
  background-color: @GBcolor !important;
}

.subMenu .ant-menu-sub .ant-menu-submenu-open > .ant-menu-submenu-title {
  padding-left: 20px !important;
  text-align: center;
}

.ant-menu-item-active {
  color: rgb(226, 128, 3) !important;
}

.ant-menu-submenu-arrow::before {
  color: #fff;
  background-image: none;
}

.ant-menu-submenu-arrow::after {
  color: #fff;
  background-image: none;
}

// 后加
// .ant-menu-inline > .ant-menu-item > a:hover,
// .subMenu .ant-menu-submenu .ant-menu-item:hover {
//   background-color: #fff;
//   border-radius: 20px;
//   padding: 0 22px !important;
// }
// // 没有下级的菜单展开时
// .ant-menu-inline > .ant-menu-item > a {
//   padding-left: 24px !important;
// }
// // 所有级菜单清除padding
// .subMenu .ant-menu-item {
//   padding: 0 !important;
// }
// .subMenu .ant-menu-submenu > a {
//   padding: 0 22px !important;
// }
.subMenu .ant-menu-submenu .ant-menu-item > a {
  //padding-left:0 !important;
  // padding: 0 60px !important;
  // text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  -o-text-overflow: ellipsis;
  color: #fff !important;
  margin-bottom: 4px;
}

.subMenu .ant-menu-item a:hover span {
  color: rgb(226, 128, 3) !important;
}
.subMenu {
  background-color: #3154a4 !important;
}
/*.ant-menu-dark {
  background-color: #3154a4 !important;
}*/

.ant-menu-dark .ant-menu-sub {
  background-color: #3154a4 !important;
}

.ant-layout-sider {
  background: #3154a4 !important;
}
</style>
<!-- update_end author:sunjianlei date:20190530 for: 选中首页的时候不显示背景颜色 -->
